<template>
<div>
  <!-- <div class="pop_div"></div> -->
  <div class="deviceRelate">
       <IconTitle
                class="selfTitle"
                title="选择单个设备"
                imgUrl="yunwei"
              />
              <div class="firstTitle">
                  操作
              </div>
    
    <div class="action">
      <el-row :gutter="10">
        <el-col :span="5">
          <div class="actionLeft">
            <div class="kinds">
              <span
                v-for="(item, index) in chooseList"
                :key="index"
                :class="{ active: ischoosed == index }"
                >{{ item.name }}</span
              >
            </div>
            <div class="treeList">
              <el-tree
                :data="dataDev"
                :props="defaultProps"
                @node-click="handleNodeClick"
              ></el-tree>
            </div>
          </div>
        </el-col>
       
       
        <el-col :span="19">
          <div class="boxCard">
            <!-- <el-input placeholder="请输入内容" >
              <i slot="suffix" class="el-input__icon el-icon-search"></i>
            </el-input> -->
            <div class="tableStyle">
                
                <div class="headerTable">
                    <span >设备编号</span>
                    <span >设备名称</span>
                    <span >资产编号</span>

                    <span >类别</span>
                    <span >负责人</span>
                    <span >规格型号</span>

                     <span >所属部门</span>
                    <span >位置</span>
                    <span >单位</span>
                </div>
                <div v-for="item,index in tableList" :key="index" :class="{'isdevChoosed':isdevChoosed==index}" @click="choose(item,index)">
                    <span>{{item.deviceName}}</span>
                    <span >{{item.deviceNum}}</span>
                    <span >{{item.assetNum}}</span>
                    <span >{{item.category}}</span>
                    <span>{{item.liableUser}}</span>
                    <span >{{item.specification}}</span>
                    <span >{{item.deptName}}</span>
                    <span >{{item.location}}</span>
                     <span >{{item.factoryNumber}}</span>
                </div>
            </div>
            </div>
            <div style="text-align:center;margin-top:20px">
                <el-pagination
  background
  :pager-count="5"
  layout="prev, pager, next"
 small
 :page-size="5"
 @current-change="handleCurrentChange"
 :current-page.sync="currentPage"
  :total="total">
</el-pagination>
            </div>
          
        </el-col>
      </el-row>
    </div>
  </div>
  <div style="text-align:center;margin-top:20px">
      <el-button type="text" style="color:#262626" @click="cancel">取消</el-button>
      <el-button type="primary" icon="el-icon-check" @click="comfireBtn">确认</el-button>
  </div>
</div>
</template>
<script>
import IconTitle from "@/components/icon-title/index.vue";
import {
  treeList,treeTable,addDev
} from "@/api/ems/inspection/dev";
export default {
    name: "singleDevice",
    props:{
        width:String
    },
    components: {
    IconTitle,
  },
  data() {
    return {
      ischoosed: 0,
      currentPage:1,
      isdevChoosed:-1,
      isnewdevChoosed:-1,
      chooseList: [
        {
          name: "类别",
        },
        {
          name: "位置",
        },
      ],
      defaultProps: {
        children: "children",
        label: "name",
      },
      dataDev: [],
      tableList:[],
      
      categoryId:'',
      deviceName:'',
        total:0
    };
  },
  mounted(){
    treeList().then((res)=>{
      this.dataDev = res.data.data
    })
    this.getTreeList();
  },
  methods: {
    getTreeList(){
     treeTable({categoryId:this.categoryId,deviceName:this.deviceName,size:5,current:this.currentPage}).then((res)=>{
        this.tableList=res.data.data.records;
        this.total = res.data.data.total
        // console.log(this.tableList)
      })
    },
     handleCurrentChange(index){
        this.currentPage = index;
        this.getTreeList();
    },
    handleNodeClick(data) {
      this.categoryId = data.id;
      this.getTreeList()
      // console.log(data);
    },
    cancel(){
      this.$emit('cancel')
    },
    
    choose(item,index){
      this.isdevChoosed=index;
      this.newDev = item;
      // console.log(item)
    },
  
    
    comfireBtn(){
      this.$emit('tellObj',this.newDev)
    }

  },
};
</script>
<style lang="scss" scoped>
.firstTitle{
    color: #101010;
    font-size: 12px;
    margin: 20px 0;
}
.deviceRelate {
  
 
  .kinds {
    border-bottom: 1px solid #ecf0f4;
    margin-right: 10px;
    font-size: 12px;
    span {
      display: inline-block;
       width: 50%;
      text-align: center;
      font-size: 12px;
      color: #868181;
      padding: 10px 15px;
    //   margin: 0 20px;
    }
    .active {
      border-bottom: 2px solid #26ae61;
      color: #26ae61;
    }
  }
  ::v-deep.treeList {
    padding: 10px 15px;
    .el-tree-node__label{
      font-size: 12px;
      color: #606266;
    }
  }
  .actionLeft {
    border-right: 1px solid #ecf0f4;
    // height: 40vh;
  }
  .boxCard {
      padding: 10px;
    border: 1px solid rgba(236, 240, 244, 100);
  }
  .tableStyle{
      //font-size: 12px;
      margin: 0;
      cursor: pointer;
      font-size: 12px;
      .headerTable{
        display: flex;
        background-color: #F4F7FC;
          span{
              flex: 1;
          }
      }
      div{
        //   display: flex;
         display: flex ;
          padding: 10px ;
          span{
              flex:1;
             display: inline-block;
             overflow: hidden;
             //word-break: break-all;
             text-overflow: ellipsis;
             white-space:nowrap;
             padding: 0 5px;
          }
          // .cols{
          //     width: 40%;
          // }
          // .colsm{
          //     width:10% ;
          // }
          // .colsx{
          //      width:25% ;
          // }
      }
  }
  .el-button--primary{
      background-color: #26AE61;
      border-color: #26AE61;
      margin-bottom: 20px;
      margin-top: 30px;
      font-size: 12px;
  }
  .el-button--danger{
      background-color: #E74C3D;
      border-color: #E74C3D;
      font-size: 12px;
  }
  .button{
      div{
          text-align: center;
      }
  }
}
.isdevChoosed{
    background-color:rgba(39, 182, 106, 0.41);
    
}

</style>